import React, { useState, useEffect } from "react";
import { Image, View } from "@tarojs/components";
import classNames from "classnames";
import default_img from "@/images/default_img.jpg";

import "./index.scss";

const Index: React.FC<any> = (props: any) => {
  const [isFail, setIsFail] = useState(false);

  const onError = () => {
    setIsFail(true);
  };

  return isFail ? (
    <View
      className={classNames(
        "customer-image-component",
        props.className && props.className
      )}
      style="display:flex;"
    >
      <Image className="customer-image" src={default_img} mode="widthFix" />
    </View>
  ) : (
    <Image
      {...props}
      lazyLoad
      showMenuByLongpress
      className={props.className}
      onError={onError}
      src={props.src}
    />
  );
};

export default Index;
